var ysb={};

layui.use('table', function(){
  var table = layui.table;
  var $ = layui.jquery;
  var token=localStorage.getToken;
  ysb.init=function(){
	  layer.load(1);
	  var orgName="",creditCard="",orgType="";
	  try{
		  orgName=$("#orgName").val();
		  creditCard=$("#creditCard").val();
		  orgType=$("#orgType").val();
	  }catch(e){}
	  table.render({
	    elem: '#orgList',
	    toolbar: '#toolbarOrg',
	    url:baseApi+'/sys/org/list',
	    where:{"token":token,"orgName":orgName,"creditCard":creditCard,"orgType":orgType},
	    cols: [[
	       {type: 'checkbox', fixed: 'left'}
	      ,{field:'orgNo', width:150, title: '企业编码'}
	      ,{field:'orgName', width:250, title: '企业名称'}
	      ,{field:'parentNo', width:150, title: '上级编码'}
	      ,{field:'parentName', width:250, title: '上级企业名称'}
	      ,{field:'orgType', width:150, title: '企业类型'}
	      ,{field:'status', width:100,title: '企业状态'}
	      ,{field:'createTime', width:180, title: '创建时间'}
	      ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:150}
	    ]],
	    done: function () {
	        layer.closeAll('loading');
	    }
	    ,page: true
	  });
};
  
  
//头工具栏事件
  table.on('toolbar(orgList)', function(obj){
    var checkStatus = table.checkStatus(obj.config.id);
    switch(obj.event){
      case 'getCheckData':
        var data = checkStatus.data;
        layer.alert(JSON.stringify(data));
      break;
      case 'getCheckLength':
        var data = checkStatus.data;
        layer.msg('选中了：'+ data.length + ' 个');
      break;
      case 'isAll':
        layer.msg(checkStatus.isAll ? '全选': '未全选');
      break;
    };
  });
  
  //监听行工具事件
  table.on('tool(orgList)', function(obj){
    var data = obj.data;
    //console.log(obj)
    if(obj.event === 'del'){
      layer.confirm('真的删除行么', function(index){
        obj.del();
        layer.close(index);
      });
    } else if(obj.event === 'edit'){
      layer.prompt({
        formType: 2
        ,value: data.email
      }, function(value, index){
        obj.update({
          email: value
        });
        layer.close(index);
      });
    }
});
  //初始化数据
  ysb.init();
  //用户点击搜索
  $('#queryBut').click(function () {
	 // ysb.init();
  });
});

